{% extends 'admin/admin_base.html' %}
{%import '_macros.html' as macros%}
    {% block title %}翻唱{% endblock %}
{% block head %}
    {{ super() }}
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
     <link rel="stylesheet" href="{{ url_for('static',filename='css/admin/admin_work.css') }}">
{% endblock %}
{% block body %}
    <div class="boong">
        <ul class="nav nav-tabs">
            <li class="active">
                <a href="{{ url_for('cover.index')}}">列表</a>
            </li>
            <li><a href="{{ url_for('cover.create', change='create') }}">增加</a></li>
            <li onclick="change()"><a href="javascript:void(0)">修改</a></li>
            <li onclick="change_de()"><a href="javascript:void(0)">删除</a></li>
            <li><div class="form-group">
                <input type="text" id="search" name="search" value="" class="col-md-2 form-control" placeholder="请输入要查找的组名"></div></li>
            <li onclick="change_ce()"><a href="javascript:void(0)">搜索</a></li>
        </ul>
        <table class="table table-striped table-bordered model-list" cellspacing="10">
            <tbody><tr class="list-title">
                <th class="list-checkbox-column">
                    <input type="checkbox" name="rowtoggle" class="action-rowtoggle" id="all" title="选择所有记录" onclick="cc()">
                </th>
                <td width="30px" style="text-align: center">ID</td>
                <td width="130px" style="text-align: center">名称</td>
                <td width="138px" style="text-align: center">歌手</td>
                <td width="138px" style="text-align: center">原唱</td>
                <td width="138px" style="text-align: center">上传时间</td>
                <td width="80" style="text-align: center">歌词</td>
                <td width="100" style="text-align: center">试听地址</td>
                <td width="150px" style="text-align: center">操作</td>
            </tr>
            {% if posts == [] %}
                <tr>
                <td colspan="999"><div class="text-center">表中没有任何记录</div></td>
                </tr>
            {% else %}
                {% for i in posts %}
                    <tr>
                        <td><input type="checkbox" name="rowid" class="action-checkbox" id="{{ loop.index }}" value="{{ loop.index }}" title="选择记录" onclick="bc()"></td>
                        <td class="list-name"><a href="#" status="1" name="{{ loop.index }}" class="tata">{{ i['id'] }}</a>
                        </td>
                        <td>
                            <div class="orange" title="{{ i['name'] }}">{{ i['name'] }}</div>
                        </td>
{#                        <td class="orange" title="{{ i['name'] }}">{{ i['name'] }}</td>#}
                        <td title="{{ i['singer'] }}">{{ i['singer'] }} </td>
                        <td title="{{ i['Original_song'] }}">{{ i['Original_song'] }}</td>
                        <td title="{{ i['time'] }}">{{ i['time'] }}</td>
                        <td style="text-align: center"><p><a href="javascript:void(0)" class="click_pop" onclick="op({{ i['id'] }})">查看</a></p></td>
                        <td style="text-align: center"><p class="fn-left"><a href="{{ i['Address'] }}"  target="_blank">前往</a></p></td>
                        <td><a href="{{ url_for('cover.create', change='check',number=i['id'])}}" class="list-btn btn-orange">查看</a>
                            <a href="{{ url_for('cover.create', change='change',number=i['id'])}}" class="list-btn btn-orange">修改</a>
                            <a href="javascript:void(0)" onclick="hh({{ i['id'] }})" class="list-btn btn-orange">删除</a>
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
                </table>
                <div class="bgPop"></div>
                    <div class="pop">
                        <div class="pop-content">
                            <p style="font-size:150%" id="textttt"></p>
                        </div>
                    </div>
                <script>
                    $(document).ready(function () {
                        $('.bgPop').click(function () {
                            $('.bgPop,.pop').hide();
                        });
                        $('.click_pop').click(function () {
                            $('.bgPop,.pop').show();
                        });
                    });
                </script>
               {{macros.pagination_widget(pagination,'cover.index')}}
            {% endif %}
{#    <ul class="breadcrumb"  onclick="gg()" id="fenye">#}
    </div>
{% endblock %}
{% block tail %}
    {{ super() }}
{#    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>#}
    <script type="text/javascript">
        function op(a) {
            jQuery.get("{{ url_for('cover.create_2')}}", { Lyric: a}, function (cc) {
                    $('#textttt').html(cc.message);
                });
        }
        function cc() {
            var gr = document.getElementById('all');
            var mq = document.getElementsByName('rowid');
            if (gr.checked){
                for(i=0;i<mq.length;i++){
                    mq[i].checked = true;
                }
            }else{
                for(i=0;i<mq.length;i++){
                    mq[i].checked = false;
                }
            }
        }
        function bc() {
            var mq = document.getElementsByName('rowid');
        }
{#        修改#}
        function change() {
            var gr = document.getElementById('all');
            var um = 0;
            var vp = 'NULL';
            var vm = 'NULL';
            if(gr.checked){
                alert("只能选择一项");
                return false;
            }else{
                var mq = document.getElementsByName('rowid');
                var mb = document.getElementsByClassName('tata');
                for(i=0;i<mq.length;i++){
                    if(mq[i].checked){
                        um +=1;
                        if(um==1){
                            vp = mq[i].value;
                            vm = mb[i].text;
                        }else{
                            alert("只能选择一项");
                            return false;
                        }
                    }
                }
                if(vp=='NULL'){
                    alert("请选择一项");
                    return false;
                }
                location.href="{{ url_for('cover.create', change='change')}}?number="+vm;
            }
        }
        function hh(i) {
            var mymessage=confirm("确认删除?");
            if(mymessage==true){
                location.href="{{ url_for('cover.create', change='delete')}}?number="+i;
            }else{
                return false;
            }
        }
        function change_de() {
            var ll_grac = new Array();
            var num = 0;
            var mq_val = document.getElementsByName('rowid');
            var mb = document.getElementsByClassName('tata');
            for(k in mq_val){
                if(mq_val[k].checked){
{#                    ll_grac.push(mb[k].text);#}
                    ll_grac[num]=mb[k].text;
                    num +=1;
                }
            }
            if(ll_grac=='') {
                alert('请至少选择一项');
                return false;
            }
            var mymessage=confirm("确认删除?");
            if(mymessage==true){
                location.href="{{ url_for('cover.create', change='delete')}}?number="+JSON.stringify(ll_grac);
            }else{
                return false;
            }
        }
        function change_ce() {
            var mu = document.getElementById('search').value;
            if(mu ==''){
                alert('请输入要搜索的组名')
                return false;
            }else{
                location.href="{{ url_for('cover.index')}}?search="+mu;
            }
        }
    </script>
{% endblock %}